/*
 * @Author: hans
 * @Date:   2017-11-30 18:16:22
 * @Last Modified by:   hans
 * @Last Modified time: 2017-12-18 17:05:09
 */

'use strict';

$(function() {
    //音乐路径
    var musicSrc = './css/sound_exam_bg2.mp3';
    var audio = null;

    function setAudio() {
        audio = document.createElement('audio');
        audio.src = musicSrc;
        if (!audio) {
            audio.load(); //加载音乐
        } else {
            audio.play();
            audio.loop = true; //循环播放
        }
    }
    var musicBtn = $('.myMusic');
    var $music = musicBtn.find('.circle');
    //控制
    musicBtn.off().on('click', function() {
        if ($music.hasClass('play')) { //如果已经播放，则暂停
            audio && (audio.pause());
            $music.addClass('pause').removeClass('play').addClass('music_closed').removeClass('music_play');
        } else {
            audio && (audio.play());
            $music.addClass('play').removeClass('pause').addClass('music_play').removeClass('music_closed');;
        }
    });
    //页面加载后执行
    window.onload = function() {
        setAudio();
    }



});